#version 330 core

in vec2 TexCoords;

uniform float Time;
uniform vec2 MousePos;
uniform vec2 Size;
uniform sampler2D image;
uniform sampler2D imageMask;
uniform sampler2D imageNoise;
uniform float DrawBg;

float maskWidth = 20.0;
const float strength = 1.1;

out vec4 FragColor;

void main()
{
	if(DrawBg > 0.0)
	{
		FragColor = texture2D(image, TexCoords);
	}
	else{
		
		vec2 pixel_num = vec2(textureSize(image, 0) / maskWidth);
		vec2 pixel_uv = floor(TexCoords * pixel_num) / pixel_num;
		vec4 noise_color = texture2D(imageNoise, pixel_uv + sin(Time));

		//vec4 color = texture2D(image, pixel_uv); //不动的
			float nosise_value = noise_color.r;
			if(nosise_value > 0.4){
				nosise_value *= -1.0;
			}
			
			vec4 color =  texture2D(image, vec2(nosise_value) * strength);
		
		if(TexCoords.x < MousePos.x - Size.x/2.0){
			color.a = 0.0;
		}
		else if(TexCoords.x > MousePos.x + Size.x/2.0){
			color.a = 0.0;
		}
		else if(TexCoords.y < MousePos.y - Size.x/2.0){
			color.a = 0.0;
		}
		else if(TexCoords.y > MousePos.y + Size.y/2.0){
			color.a = 0.0;
		}
		
		FragColor = color;
	}
	
}
